<!doctype html>
<html class="no-js fixed-layout">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/blog/public/static/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/blog/public/static/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="/blog/public/static/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/blog/public/static/assets/css/admin.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
    以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <strong>Blog</strong> <small>后台管理模板</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li><a href="javascript:;"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning">5</span></a></li>
            <li class="am-dropdown" data-am-dropdown>
                <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
                    <span class="am-icon-users"></span> 管理员 <span class="am-icon-caret-down"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="#"><span class="am-icon-user"></span> 资料</a></li>
                    <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                    <li><a href="#"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
            <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>

<div class="am-cf admin-main">
    <!-- sidebar start -->
    <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
        <div class="am-offcanvas-bar admin-offcanvas-bar">
            <ul class="am-list admin-sidebar-list">
                <li><a href="/blog/index.php/admin/index"><span class="am-icon-home"></span> 首页</a></li>
                <li><a href="/blog/index.php/admin/post"><span class="am-icon-file"></span> 发表文章</a></li>
                <li><a href="/blog/index.php/admin/article"><span class="am-icon-table"></span> 文章管理</a></li>
                <li><a href="admin-form.html"><span class="am-icon-pencil-square-o"></span> 表单</a></li>
                <li><a href="#"><span class="am-icon-sign-out"></span> 注销</a></li>
            </ul>

            <div class="am-panel am-panel-default admin-sidebar-panel">
                <div class="am-panel-bd">
                    <p><span class="am-icon-bookmark"></span> 公告</p>
                    <p>时光静好，与君语；细水流年，与君同。—— Amaze UI</p>
                </div>
            </div>

            <div class="am-panel am-panel-default admin-sidebar-panel">
                <div class="am-panel-bd">
                    <p><span class="am-icon-tag"></span> wiki</p>
                    <p>Welcome to the Amaze UI wiki!</p>
                </div>
            </div>
        </div>
    </div>
    <!-- sidebar end -->

    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">发表文章</strong> / <small>撰写博文</small></div>
            </div>
            <hr>
            <form class="am-form">
                <fieldset>
                    <label for="cate_m">类别</label>
                    <div class="am-form-group">
                        <select id="cate_m">

                            {volist name='category_list' id='cate'}
                            <option value="{$cate.id}">{$cate.name}</option>
                            {/volist}
                        </select>
                        <br>
                        <div></div>
                        <select id="cate_b">

                        </select>
                    </div>

                    <div class="am-form-group">
                        <label for="title">标题</label>
                        <input type="text" class="" id="title" placeholder="输入标题">
                    </div>

                    <div class="am-form-group">
                        <label for="tag">标签</label>
                        <input type="text" class="" id="tag" placeholder="添加标签">
                    </div>

                    <div class="am-form-group">
                        <label for="wangEdit">正文</label>
                        <div id="wangEdit" style="height: 320px;"></div>
                    </div>
                    <p><button type="button" class="am-btn am-btn-default" onclick="post()">提交</button></p>
                </fieldset>
            </form>
        </div>
    </div>

    <!-- 测试弹出层 start-->
    <div class="am-modal am-modal-alert" tabindex="-1" id="success_alert">
        <div class="am-modal-dialog">

            <img class="am-modal-hd" src="/blog/public/static/assets/img/success.png">
            <div class="am-modal-bd">
                发表成功！
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn">确定</span>
            </div>
        </div>
    </div>
    <!-- 测试弹出层 end-->


    <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/blog/public/static/assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/blog/public/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/blog/public/static/assets/js/amazeui.min.js"></script>
<script src="/blog/public/static/assets/js/amazeui.dialog.min.js"></script>
<script src="/blog/public/static/assets/js/app.js"></script>
<script src="/blog/public/static/vendor/wangEditor/dist/js/wangEditor.min.js"></script>
<link rel="stylesheet" href="/blog/public/static/vendor/wangEditor/dist/css/wangEditor.min.css">
<script type="text/javascript">
    var editor = new wangEditor('wangEdit');
    editor.create();
</script>
<script type="text/javascript">
    var category_m_id='';
    var category_b_id=''
    $(function () {
        category_m_id=$("#cate_m").val();
        $("#cate_b").empty();
        $.post("/blog/index.php/admin/post/cate_b",{"pid":$("#cate_m").val()},function (data) {
            if (data==0){
                alert('为空');
                $("#cate_b").attr("class","am-form-field");
                $("#cate_b").append("disabled");
            }
            //$("#cate_b").append("<option selected value=''></option>")
            $.each(data,function () {
                $("#cate_b").append("'<option value='"+this.id+"'>"+this.name+"</option>'");
            })

        },"json")
    })
    $("#cate_m").on('change',function () {
        category_m_id=$(this).val();
        $("#cate_b").empty();
        $.post("/blog/index.php/admin/post/cate_b",{"pid":$(this).val()},function (data) {
            if (data==0){
                alert('为空');
                $("#cate_b").attr("class","am-form-field");
                $("#cate_b").append("disabled");
            }
            //$("#cate_b").append("<option selected value=''></option>")
            $.each(data,function () {
                $("#cate_b").append("'<option value='"+this.id+"'>"+this.name+"</option>'");
            })

        },"json")
    });
    $("#cate_b").on('change',function () {
        category_b_id=$(this).val();
    });
    function post() {
        //alert("category_m_id"+category_m_id+"category_b_id"+category_b_id);
        var content=editor.$txt.html();
        var title=$("#title").val();
        var tag=$("#tag").val();
        var intro=editor.$txt.text();
        $.ajax({
            url:"/blog/index.php/admin/post/post",
            type:"post",
            data:{"title":title,"content":content,"tag":tag,"intro":intro,"category_m_id":category_m_id,"category_b_id":category_b_id},
            dataType:"json",
            success:function (data) {
                if (data=='success'){
                    //$("#success_alert").modal(); 弹出层使用
                    AMUI.dialog.alert({
                        content:'发表成功！',
                        onConfirm: function() {
                            console.log('close');
                        }
                    });

                }
            },
            error:function (jqXHR) {
                alert("AJAX错误，返回状态："+jqXHR.status);
            }
        })
    }
</script>
</body>
</html>





